package com.dtw.ditouwang.ui.mine;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.HelpBeanList;
import com.dtw.ditouwang.ui.OnItemClickListener;

import java.util.List;

public class HelpTopAdapter extends RecyclerView.Adapter<HelpTopAdapter.Holder> {
    List<HelpBeanList.DataBean> helpTopList;
    OnItemClickListener onItemClickListener;

    public HelpTopAdapter(List<HelpBeanList.DataBean> helpTopList) {
        this.helpTopList = helpTopList;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new Holder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_help, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        holder.title.setText(helpTopList.get(position).getTitle());
    }

    @Override
    public int getItemCount() {
        return helpTopList.size();
    }

    class Holder extends RecyclerView.ViewHolder {
        TextView title;

        public Holder(View itemView) {
            super(itemView);
            title = itemView.findViewById(R.id.text_title);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(onItemClickListener!=null){
                        onItemClickListener.onItemClick(0,getAdapterPosition(),helpTopList.get(getAdapterPosition()).getId());
                    }
                }
            });
        }
    }
}
